package com.common.common;

import java.io.File;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSocketFactory;

import okhttp3.Cache;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;

public class HttpConfig {

    private OkHttpClient.Builder okHttpBuilder;
    private Retrofit.Builder retrofitBuilder;
    //超时时间
    private long timeout = 5000L;//连接超时时间，默认5S
    //缓存
    private Cache httpCache;//Http缓存对象
    //https相关
    private HostnameVerifier hostnameVerifier;//主机域名验证
    private SSLSocketFactory sslSocketFactory;//SSL工厂
    //主URL
    private String baseUrl;
    private File cacheFile;
    private int httpCacheSize = 10 * 1024 * 1024;

    public HttpConfig() {
    }

    public OkHttpClient.Builder getOkHttpBuilder() {
        return okHttpBuilder;
    }

    public HttpConfig setOkHttpBuilder(OkHttpClient.Builder okHttpBuilder) {
        this.okHttpBuilder = okHttpBuilder;
        return this;
    }

    public Retrofit.Builder getRetrofitBuilder() {
        return retrofitBuilder;
    }

    public HttpConfig setRetrofitBuilder(Retrofit.Builder retrofitBuilder) {
        this.retrofitBuilder = retrofitBuilder;
        return this;
    }


    public long getTimeout() {
        return timeout;
    }

    public HttpConfig setTimeout(long timeout) {
        this.timeout = timeout;
        return this;
    }


    public Cache getHttpCache() {
        return httpCache;
    }

    public HttpConfig setHttpCache(Cache httpCache) {
        this.httpCache = httpCache;
        return this;
    }

    public HttpConfig setHttpCache(File cacheFile) {
        this.cacheFile = cacheFile;
        this.httpCache = new Cache(new File(cacheFile, "httpCache"), httpCacheSize);
        return this;
    }

    public HostnameVerifier getHostnameVerifier() {
        return hostnameVerifier;
    }

    public HttpConfig setHostnameVerifier(HostnameVerifier hostnameVerifier) {
        this.hostnameVerifier = hostnameVerifier;
        return this;
    }

    public SSLSocketFactory getSslSocketFactory() {
        return sslSocketFactory;
    }

    public HttpConfig setSslSocketFactory(SSLSocketFactory sslSocketFactory) {
        this.sslSocketFactory = sslSocketFactory;
        return this;
    }


    public String getBaseUrl() {
        return baseUrl;
    }

    public HttpConfig setBaseUrl(String baseUrl) {
        this.baseUrl = baseUrl;
        return this;
    }

    public File getCacheFile() {
        return cacheFile;
    }

    public void setCacheFile(File cacheFile) {
        this.cacheFile = cacheFile;
    }

    public int getHttpCacheSize() {
        return httpCacheSize;
    }

    public void setHttpCacheSize(int httpCacheSize) {
        this.httpCacheSize = httpCacheSize;
    }
}
